package com.situ.day2;

import org.junit.Test;

public class OOPDemo {

    @Test
    public void test1() {
        Student student1 = new Student();
        student1.id = 1;
        student1.name = "zhangsan";
        student1.age = 22;
        student1.gender = "男";
        //Student: {id=1,name=zhangsan,age=23}
        //System.out.println(student1.name);
        //System.out.println("Student: {id="+student1.id+",name="+student1.name+",age="+student1.age+"}");
        System.out.println(student1.getInfo());
        System.out.println(student1.toString());
        //直接打印对象，默认调用toString()
        System.out.println(student1);

        Student student2 = new Student();
        student2.id = 2;
        student2.name = "lisi";
        student2.age = 18;
        student2.gender = "女";
        //System.out.println(student2.name);
        System.out.println(student2.getInfo());
        System.out.println(student2.toString());
        System.out.println(student2);
    }

    @Test
    public void test2() {
        Student student = new Student();
        System.out.println(student.id);
        System.out.println(student.name);
        System.out.println(student.money);
    }

    @Test
    public void test3() {
        int[] array1 = new int[3];
        boolean[] array2 = new boolean[3];
        Student[] students = new Student[3];
        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i]);
        }
        for (Student student : students) {
            System.out.println(student);
        }
    }

    @Test
    public void test4() {
        Student student = null;
        System.out.println(student);// null
        // null.属性   null.方法()
        //java.lang.NullPointerException: Cannot read field "id" because "student" is null
        System.out.println(student.id);
    }
}
